//
//  OrderHeaderView.m
//  Peso Guide
//
//  Created by macbook on 2025/6/11.
//

#import "OrderHeaderView.h"

@interface OrderHeaderView ()

@property (nonatomic, strong) UIImageView *backImg;
@property (nonatomic, strong) UIImageView *rightImg;
@property (nonatomic, strong) UILabel *titLabel;
@property (nonatomic, strong) UIView *chooseView;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, assign) BOOL isLoad;

@end

@implementation OrderHeaderView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _backImg = [PesoKit createImageViewWithFrame:CGRectMake(0, 0, KScreenWidth, 155) imageNamed:@""];
        _backImg.backgroundColor = ColorHex(@"#1A7A35");
        [self addSubview:_backImg];
        
        _rightImg = [PesoKit createImageViewWithFrame:CGRectMake(KScreenWidth-13-150, 0, 150, 150) imageNamed:@"ic_order_top"];
        [_backImg addSubview:_rightImg];
        
        _titLabel = [PesoKit createLabelWithFrame:CGRectMake(24, (100-38)/2.0, KScreenWidth-15-150-24-10, 38) backGroundColor:[UIColor clearColor] text:[Lang set:@"Getting into debt is no\nlonger difficult."] textColor:ColorHex(@"#FFFFFF") font:[UIFont fontWithName:@"PoetsenOne-Regular" size:16]];
        _titLabel.numberOfLines = 0;
        [_backImg addSubview:_titLabel];
        [_titLabel sizeToFit];
        
        _chooseView = [PesoKit createViewWithFrame:CGRectMake(0, 100, KScreenWidth, 55) backGroundColor:ColorHex(@"#FFFFFF")];
        _chooseView.layer.mask = [AppTools clipTopRightAndLeftByRoundingCorners:_chooseView radii:CGSizeMake(15.0f, 15.0f)];
        [self addSubview:_chooseView];
        
        NSArray *titleArr = @[[Lang set:@"All"],[Lang set:@"Apply"],[Lang set:@"Repayment"],[Lang set:@"Finished"]];
        for (int i = 0; i < 4; i++) {
            UIButton *itemButton = [PesoKit createButtonWithFrame:CGRectMake(KScreenWidth/4.0*i, 12, KScreenWidth/4.0, 22) backGroundColor:[UIColor whiteColor] title:[titleArr safeObjectAtIndex:i] titleColor:ColorHex(@"#000000") font:FONT(FontWeightStyleRegular, 16)];
            itemButton.tag = 888+i;
            [itemButton addTarget:self action:@selector(itemButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            [_chooseView addSubview:itemButton];
        }
        
        _lineView = [PesoKit createViewWithFrame:CGRectMake((KScreenWidth/4.0-33)/2.0, 38, 33, 3) backGroundColor:ColorHex(@"#1A7A35")];
        [_chooseView addSubview:_lineView];
    }
    return self;
}

- (void)itemButtonClick:(UIButton *)sender {
    NSInteger tag = sender.tag-888;
    [_orderVC chooseOrderType:tag];
    
    _lineView.frame = CGRectMake(KScreenWidth/4.0*tag+(KScreenWidth/4.0-33)/2.0, 38, 33, 3);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
